﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ToDoList.Logic
{
   public class UserLogic
    {
        
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="NikeName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public int Register(string password,string nikeName)
        {
            User userList = new User();
            userList.UserId = Initialize.UserList.Max(user=>user.UserId)+1;                                                                               
            userList.NikeName = nikeName;
            userList.Password = password;
            Initialize.UserList.Add(userList);
            return userList.UserId;                  
        }

        /// <summary>
    /// 用户登录
    /// </summary>
    /// <param name="NikeName"></param>
    /// <param name="Password"></param>
    /// <returns></returns>
        public bool Login(int userId,string password)
        {           
            var User = Initialize.UserList.SingleOrDefault(user=>user.UserId==userId && user.Password.Equals(password));           
            if (User != null )
                return true;
            else
                return false;
        }

        /// <summary>
        /// 查看未完成事项
        /// </summary>
        /// <param name="ItemList"></param>
        /// <returns></returns>
        public List<Item> UnfinishedItem(List<Item> itemList)
        {
            List<Item> unfinishedItem = new List<Item>();            
            unfinishedItem = Initialize.ItemList.Where(item => !item.State).ToList();
            return unfinishedItem;
        }

        /// <summary>
        /// 查看所有事项
        /// </summary>
        /// <returns></returns>
        public List<Item> ViewAllItemList(int id)
        {
            List<Item> AllItemList =Initialize.ItemList.Where(item => item.UserID == id).ToList();           

            return AllItemList;
        }
        
        /// <summary>
        /// 提醒用户已过期的事项
        /// </summary>
        /// <param name="ItemList"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public List<Item> ItemRemind(List<Item> itemList,int userId)
        {
            List<Item> outDataItem = new List<Item>();           
            outDataItem = Initialize.ItemList.Where(item =>item.UserID==userId && item.TimeOfExpiration<DateTime.Now).ToList();
            return outDataItem;
        }
       
    }
}
